package com.example.bigworkdemo.web.controller;

import com.example.bigworkdemo.bean.user;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/api")
@ResponseBody
public class permitController {
    @GetMapping(value = "/getPermitInfoById/{id}",produces = "application/text;charset=utf-8")
    public String getPermitInfoById(@PathVariable Integer id){
        if(id == 1001){
            user u1 =new user("test1",1001,"123456","1532893@qq.com","2020-12-12");
            u1.setPermit("管理员");
            return "管理员";
        }
       else if(id == 1002){
            user u2 =new user("test2",1002,"123456","1532893@qq.com","2020-12-12");
            u2.setPermit("用户");
            return "用户";
        }
       else if(id == 1003){
            user u3 =new user("test3",100,"123456","1532893@qq.com","2020-12-12");
            u3.setPermit("经理");
            return "经理";
        }
       return "不存在此用户";
    }
    @GetMapping(value = "/changeUserPermit/{id}/{permit}",produces = "application/text;charset=utf-8")
    public String changeUserPermit(@PathVariable Integer id,@PathVariable String permit){
       user u =  new user("test1",1001,"123456","1532893@qq.com","2020-12-12");
        u.setPermit("用户");
        if(id == 1001){
            u.setPermit("管理员");
            return "修改成功！";
        }
        else {
            return "不存在此用户";
        }
    }

    @GetMapping(value = "/addPermit/{permit}",produces = "application/text;charset=utf-8")
    public String addPermit(@PathVariable String permit){
        List<String> list = new ArrayList<>();
        list.add("管理员");
        list.add("用户");
        list.add("经理");
        list.add(permit);
        System.out.println(list);
        return "增加权限成功！";
    }

    @GetMapping(value = "/deletePermit/{permit}",produces = "application/text;charset=utf-8")
    public String deletePermit(@PathVariable String permit){
        List<String> list = new ArrayList<>();
        list.add("管理员");
        list.add("用户");
        list.add("经理");
        list.remove(permit);
        System.out.println(list);
        return "删除权限成功！";
    }

}
